//
//  MainWindowTableView.m
//  Shion
//
//  Created by Chris Karr on 12/18/07.
//  Copyright 2007-2008 Audacious Software. All rights reserved.
//

#import "MainWindowTableView.h"
#import "DevicesModel.h"

@implementation MainWindowTableView

- (void) awakeFromNib
{
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInterface:) name:DEVICES_UPDATED object:nil];
}

- (void) updateInterface: (NSNotification *) msg
{
	if ([[msg object] boolValue])
		[self reloadData];
}

- (NSMenu *) menuForEvent:(NSEvent *) theEvent
{
	NSInteger row = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];

	if (row != -1) 
		[self selectRow:row byExtendingSelection: NO];

	NSMenu * menu = [[NSMenu alloc] init];

	if ([self numberOfSelectedRows] > 0 && row != -1)
	{
		[menu addItemWithTitle:NSLocalizedString (@"Edit Device", nil) action:NSSelectorFromString(@"edit:") keyEquivalent:@""];
		[menu addItemWithTitle:NSLocalizedString (@"Remove Device", nil) action:NSSelectorFromString(@"remove:") keyEquivalent:@""];
	}
	else
		[menu addItemWithTitle:NSLocalizedString (@"New Device", nil) action:NSSelectorFromString(@"new:") keyEquivalent:@""];
	

	return menu;
}

@end
